package com._520it.crm.web.controller;

import com._520it.crm.domain.Account;
import com._520it.crm.domain.Vehicle;
import com._520it.crm.service.IAccountService;
import com._520it.crm.service.IVehicleService;
import com._520it.crm.util.JsonResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class VehicleController {
	@Autowired
	private IVehicleService service;


	@RequestMapping("/vehicle/list/view")
	public ModelAndView listView(ModelAndView modelAndView,
								 @RequestParam(defaultValue = "1") int current,
								 @RequestParam(defaultValue = "10") int size,
								 String vehicleModel,
								 String name,
								 String classify,
								 Integer busload,
								 String carrying,
								 String carPrice
	){
		modelAndView.setViewName("vehicle/list");
		List<Vehicle> vehicleList = service.selectPage(current,size,name,vehicleModel,classify,busload,carrying,carPrice);

		modelAndView.addObject("list",vehicleList);
		int count = service.selectPageCount(current,size,name,vehicleModel,classify,busload,carrying,carPrice);
		int totalCount = count%size==0?count/size:count/size+1;
		modelAndView.addObject("totalCount",totalCount);
		modelAndView.addObject("current",current);
		return modelAndView;
	}

	
	@RequestMapping("/vehicle/index")
	public String vehicleIndex(){
		return "vehicle/index";
	}
	
}
